#include "linkfabric/LinkFabric.hpp"
#include <iostream>
#include <unistd.h>

using namespace linkfabric;

int main() {
    LinkFabric fabric;
    if (!fabric.init("/dev/memlink0")) {
        std::cerr << "❌ Failed to map remote memory." << std::endl;
        return 1;
    }

    int ch = fabric.allocChannel(ChannelPermission::READWRITE);

    fabric.onReceive(ch, [](const std::vector<TLV>& tlvs) {
        for (const auto& tlv : tlvs) {
            std::string val(tlv.value.begin(), tlv.value.end());
            std::cout << "📥 TLV[" << int(tlv.tag) << "] = " << val << std::endl;
        }
    });

    fabric.run();

    std::vector<TLV> message = {
        TLV(0x01, {'H','e','l','l','o'}),
        TLV(0x02, {'L','i','n','k','F','a','b','r','i','c'})
    };

    fabric.send(ch, message);
    sleep(2);
    fabric.shutdown();
    return 0;
}
